/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package entityprojet;

import entityprojet.exceptions.NonexistentEntityException;
import entityprojet.exceptions.PreexistingEntityException;
import java.io.Serializable;
import javax.persistence.Query;
import javax.persistence.EntityNotFoundException;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author Ron
 */
public class FCatalogueJpaController implements Serializable {

    public FCatalogueJpaController(EntityManagerFactory emf) {
        this.emf = emf;
    }
    private EntityManagerFactory emf = null;

    public FCatalogueJpaController() {
        this.emf = Persistence.createEntityManagerFactory("projetT_RPU");
    }
    
    public EntityManager getEntityManager() {
        return emf.createEntityManager();
    }

    public void create(FCatalogue FCatalogue) throws PreexistingEntityException, Exception {
        if (FCatalogue.getFArticleCollection() == null) {
            FCatalogue.setFArticleCollection(new ArrayList<FArticle>());
        }
        if (FCatalogue.getFArticleCollection1() == null) {
            FCatalogue.setFArticleCollection1(new ArrayList<FArticle>());
        }
        if (FCatalogue.getFArticleCollection2() == null) {
            FCatalogue.setFArticleCollection2(new ArrayList<FArticle>());
        }
        if (FCatalogue.getFArticleCollection3() == null) {
            FCatalogue.setFArticleCollection3(new ArrayList<FArticle>());
        }
        if (FCatalogue.getFCatalogueCollection() == null) {
            FCatalogue.setFCatalogueCollection(new ArrayList<FCatalogue>());
        }
        EntityManager em = null;
        try {
            em = getEntityManager();
            em.getTransaction().begin();
            FCatalogue cbCLNoParent = FCatalogue.getCbCLNoParent();
            if (cbCLNoParent != null) {
                cbCLNoParent = em.getReference(cbCLNoParent.getClass(), cbCLNoParent.getCbMarq());
                FCatalogue.setCbCLNoParent(cbCLNoParent);
            }
            Collection<FArticle> attachedFArticleCollection = new ArrayList<FArticle>();
            for (FArticle FArticleCollectionFArticleToAttach : FCatalogue.getFArticleCollection()) {
                FArticleCollectionFArticleToAttach = em.getReference(FArticleCollectionFArticleToAttach.getClass(), FArticleCollectionFArticleToAttach.getCbMarq());
                attachedFArticleCollection.add(FArticleCollectionFArticleToAttach);
            }
            FCatalogue.setFArticleCollection(attachedFArticleCollection);
            Collection<FArticle> attachedFArticleCollection1 = new ArrayList<FArticle>();
            for (FArticle FArticleCollection1FArticleToAttach : FCatalogue.getFArticleCollection1()) {
                FArticleCollection1FArticleToAttach = em.getReference(FArticleCollection1FArticleToAttach.getClass(), FArticleCollection1FArticleToAttach.getCbMarq());
                attachedFArticleCollection1.add(FArticleCollection1FArticleToAttach);
            }
            FCatalogue.setFArticleCollection1(attachedFArticleCollection1);
            Collection<FArticle> attachedFArticleCollection2 = new ArrayList<FArticle>();
            for (FArticle FArticleCollection2FArticleToAttach : FCatalogue.getFArticleCollection2()) {
                FArticleCollection2FArticleToAttach = em.getReference(FArticleCollection2FArticleToAttach.getClass(), FArticleCollection2FArticleToAttach.getCbMarq());
                attachedFArticleCollection2.add(FArticleCollection2FArticleToAttach);
            }
            FCatalogue.setFArticleCollection2(attachedFArticleCollection2);
            Collection<FArticle> attachedFArticleCollection3 = new ArrayList<FArticle>();
            for (FArticle FArticleCollection3FArticleToAttach : FCatalogue.getFArticleCollection3()) {
                FArticleCollection3FArticleToAttach = em.getReference(FArticleCollection3FArticleToAttach.getClass(), FArticleCollection3FArticleToAttach.getCbMarq());
                attachedFArticleCollection3.add(FArticleCollection3FArticleToAttach);
            }
            FCatalogue.setFArticleCollection3(attachedFArticleCollection3);
            Collection<FCatalogue> attachedFCatalogueCollection = new ArrayList<FCatalogue>();
            for (FCatalogue FCatalogueCollectionFCatalogueToAttach : FCatalogue.getFCatalogueCollection()) {
                FCatalogueCollectionFCatalogueToAttach = em.getReference(FCatalogueCollectionFCatalogueToAttach.getClass(), FCatalogueCollectionFCatalogueToAttach.getCbMarq());
                attachedFCatalogueCollection.add(FCatalogueCollectionFCatalogueToAttach);
            }
            FCatalogue.setFCatalogueCollection(attachedFCatalogueCollection);
            em.persist(FCatalogue);
            if (cbCLNoParent != null) {
                cbCLNoParent.getFCatalogueCollection().add(FCatalogue);
                cbCLNoParent = em.merge(cbCLNoParent);
            }
            for (FArticle FArticleCollectionFArticle : FCatalogue.getFArticleCollection()) {
                FCatalogue oldCbCLNo1OfFArticleCollectionFArticle = FArticleCollectionFArticle.getCbCLNo1();
                FArticleCollectionFArticle.setCbCLNo1(FCatalogue);
                FArticleCollectionFArticle = em.merge(FArticleCollectionFArticle);
                if (oldCbCLNo1OfFArticleCollectionFArticle != null) {
                    oldCbCLNo1OfFArticleCollectionFArticle.getFArticleCollection().remove(FArticleCollectionFArticle);
                    oldCbCLNo1OfFArticleCollectionFArticle = em.merge(oldCbCLNo1OfFArticleCollectionFArticle);
                }
            }
            for (FArticle FArticleCollection1FArticle : FCatalogue.getFArticleCollection1()) {
                FCatalogue oldCbCLNo2OfFArticleCollection1FArticle = FArticleCollection1FArticle.getCbCLNo2();
                FArticleCollection1FArticle.setCbCLNo2(FCatalogue);
                FArticleCollection1FArticle = em.merge(FArticleCollection1FArticle);
                if (oldCbCLNo2OfFArticleCollection1FArticle != null) {
                    oldCbCLNo2OfFArticleCollection1FArticle.getFArticleCollection1().remove(FArticleCollection1FArticle);
                    oldCbCLNo2OfFArticleCollection1FArticle = em.merge(oldCbCLNo2OfFArticleCollection1FArticle);
                }
            }
            for (FArticle FArticleCollection2FArticle : FCatalogue.getFArticleCollection2()) {
                FCatalogue oldCbCLNo3OfFArticleCollection2FArticle = FArticleCollection2FArticle.getCbCLNo3();
                FArticleCollection2FArticle.setCbCLNo3(FCatalogue);
                FArticleCollection2FArticle = em.merge(FArticleCollection2FArticle);
                if (oldCbCLNo3OfFArticleCollection2FArticle != null) {
                    oldCbCLNo3OfFArticleCollection2FArticle.getFArticleCollection2().remove(FArticleCollection2FArticle);
                    oldCbCLNo3OfFArticleCollection2FArticle = em.merge(oldCbCLNo3OfFArticleCollection2FArticle);
                }
            }
            for (FArticle FArticleCollection3FArticle : FCatalogue.getFArticleCollection3()) {
                FCatalogue oldCbCLNo4OfFArticleCollection3FArticle = FArticleCollection3FArticle.getCbCLNo4();
                FArticleCollection3FArticle.setCbCLNo4(FCatalogue);
                FArticleCollection3FArticle = em.merge(FArticleCollection3FArticle);
                if (oldCbCLNo4OfFArticleCollection3FArticle != null) {
                    oldCbCLNo4OfFArticleCollection3FArticle.getFArticleCollection3().remove(FArticleCollection3FArticle);
                    oldCbCLNo4OfFArticleCollection3FArticle = em.merge(oldCbCLNo4OfFArticleCollection3FArticle);
                }
            }
            for (FCatalogue FCatalogueCollectionFCatalogue : FCatalogue.getFCatalogueCollection()) {
                FCatalogue oldCbCLNoParentOfFCatalogueCollectionFCatalogue = FCatalogueCollectionFCatalogue.getCbCLNoParent();
                FCatalogueCollectionFCatalogue.setCbCLNoParent(FCatalogue);
                FCatalogueCollectionFCatalogue = em.merge(FCatalogueCollectionFCatalogue);
                if (oldCbCLNoParentOfFCatalogueCollectionFCatalogue != null) {
                    oldCbCLNoParentOfFCatalogueCollectionFCatalogue.getFCatalogueCollection().remove(FCatalogueCollectionFCatalogue);
                    oldCbCLNoParentOfFCatalogueCollectionFCatalogue = em.merge(oldCbCLNoParentOfFCatalogueCollectionFCatalogue);
                }
            }
            em.getTransaction().commit();
        } catch (Exception ex) {
            if (findFCatalogue(FCatalogue.getCbMarq()) != null) {
                throw new PreexistingEntityException("FCatalogue " + FCatalogue + " already exists.", ex);
            }
            throw ex;
        } finally {
            if (em != null) {
                em.close();
            }
        }
    }

    public void edit(FCatalogue FCatalogue) throws NonexistentEntityException, Exception {
        EntityManager em = null;
        try {
            em = getEntityManager();
            em.getTransaction().begin();
            FCatalogue persistentFCatalogue = em.find(FCatalogue.class, FCatalogue.getCbMarq());
            FCatalogue cbCLNoParentOld = persistentFCatalogue.getCbCLNoParent();
            FCatalogue cbCLNoParentNew = FCatalogue.getCbCLNoParent();
            Collection<FArticle> FArticleCollectionOld = persistentFCatalogue.getFArticleCollection();
            Collection<FArticle> FArticleCollectionNew = FCatalogue.getFArticleCollection();
            Collection<FArticle> FArticleCollection1Old = persistentFCatalogue.getFArticleCollection1();
            Collection<FArticle> FArticleCollection1New = FCatalogue.getFArticleCollection1();
            Collection<FArticle> FArticleCollection2Old = persistentFCatalogue.getFArticleCollection2();
            Collection<FArticle> FArticleCollection2New = FCatalogue.getFArticleCollection2();
            Collection<FArticle> FArticleCollection3Old = persistentFCatalogue.getFArticleCollection3();
            Collection<FArticle> FArticleCollection3New = FCatalogue.getFArticleCollection3();
            Collection<FCatalogue> FCatalogueCollectionOld = persistentFCatalogue.getFCatalogueCollection();
            Collection<FCatalogue> FCatalogueCollectionNew = FCatalogue.getFCatalogueCollection();
            if (cbCLNoParentNew != null) {
                cbCLNoParentNew = em.getReference(cbCLNoParentNew.getClass(), cbCLNoParentNew.getCbMarq());
                FCatalogue.setCbCLNoParent(cbCLNoParentNew);
            }
            Collection<FArticle> attachedFArticleCollectionNew = new ArrayList<FArticle>();
            for (FArticle FArticleCollectionNewFArticleToAttach : FArticleCollectionNew) {
                FArticleCollectionNewFArticleToAttach = em.getReference(FArticleCollectionNewFArticleToAttach.getClass(), FArticleCollectionNewFArticleToAttach.getCbMarq());
                attachedFArticleCollectionNew.add(FArticleCollectionNewFArticleToAttach);
            }
            FArticleCollectionNew = attachedFArticleCollectionNew;
            FCatalogue.setFArticleCollection(FArticleCollectionNew);
            Collection<FArticle> attachedFArticleCollection1New = new ArrayList<FArticle>();
            for (FArticle FArticleCollection1NewFArticleToAttach : FArticleCollection1New) {
                FArticleCollection1NewFArticleToAttach = em.getReference(FArticleCollection1NewFArticleToAttach.getClass(), FArticleCollection1NewFArticleToAttach.getCbMarq());
                attachedFArticleCollection1New.add(FArticleCollection1NewFArticleToAttach);
            }
            FArticleCollection1New = attachedFArticleCollection1New;
            FCatalogue.setFArticleCollection1(FArticleCollection1New);
            Collection<FArticle> attachedFArticleCollection2New = new ArrayList<FArticle>();
            for (FArticle FArticleCollection2NewFArticleToAttach : FArticleCollection2New) {
                FArticleCollection2NewFArticleToAttach = em.getReference(FArticleCollection2NewFArticleToAttach.getClass(), FArticleCollection2NewFArticleToAttach.getCbMarq());
                attachedFArticleCollection2New.add(FArticleCollection2NewFArticleToAttach);
            }
            FArticleCollection2New = attachedFArticleCollection2New;
            FCatalogue.setFArticleCollection2(FArticleCollection2New);
            Collection<FArticle> attachedFArticleCollection3New = new ArrayList<FArticle>();
            for (FArticle FArticleCollection3NewFArticleToAttach : FArticleCollection3New) {
                FArticleCollection3NewFArticleToAttach = em.getReference(FArticleCollection3NewFArticleToAttach.getClass(), FArticleCollection3NewFArticleToAttach.getCbMarq());
                attachedFArticleCollection3New.add(FArticleCollection3NewFArticleToAttach);
            }
            FArticleCollection3New = attachedFArticleCollection3New;
            FCatalogue.setFArticleCollection3(FArticleCollection3New);
            Collection<FCatalogue> attachedFCatalogueCollectionNew = new ArrayList<FCatalogue>();
            for (FCatalogue FCatalogueCollectionNewFCatalogueToAttach : FCatalogueCollectionNew) {
                FCatalogueCollectionNewFCatalogueToAttach = em.getReference(FCatalogueCollectionNewFCatalogueToAttach.getClass(), FCatalogueCollectionNewFCatalogueToAttach.getCbMarq());
                attachedFCatalogueCollectionNew.add(FCatalogueCollectionNewFCatalogueToAttach);
            }
            FCatalogueCollectionNew = attachedFCatalogueCollectionNew;
            FCatalogue.setFCatalogueCollection(FCatalogueCollectionNew);
            FCatalogue = em.merge(FCatalogue);
            if (cbCLNoParentOld != null && !cbCLNoParentOld.equals(cbCLNoParentNew)) {
                cbCLNoParentOld.getFCatalogueCollection().remove(FCatalogue);
                cbCLNoParentOld = em.merge(cbCLNoParentOld);
            }
            if (cbCLNoParentNew != null && !cbCLNoParentNew.equals(cbCLNoParentOld)) {
                cbCLNoParentNew.getFCatalogueCollection().add(FCatalogue);
                cbCLNoParentNew = em.merge(cbCLNoParentNew);
            }
            for (FArticle FArticleCollectionOldFArticle : FArticleCollectionOld) {
                if (!FArticleCollectionNew.contains(FArticleCollectionOldFArticle)) {
                    FArticleCollectionOldFArticle.setCbCLNo1(null);
                    FArticleCollectionOldFArticle = em.merge(FArticleCollectionOldFArticle);
                }
            }
            for (FArticle FArticleCollectionNewFArticle : FArticleCollectionNew) {
                if (!FArticleCollectionOld.contains(FArticleCollectionNewFArticle)) {
                    FCatalogue oldCbCLNo1OfFArticleCollectionNewFArticle = FArticleCollectionNewFArticle.getCbCLNo1();
                    FArticleCollectionNewFArticle.setCbCLNo1(FCatalogue);
                    FArticleCollectionNewFArticle = em.merge(FArticleCollectionNewFArticle);
                    if (oldCbCLNo1OfFArticleCollectionNewFArticle != null && !oldCbCLNo1OfFArticleCollectionNewFArticle.equals(FCatalogue)) {
                        oldCbCLNo1OfFArticleCollectionNewFArticle.getFArticleCollection().remove(FArticleCollectionNewFArticle);
                        oldCbCLNo1OfFArticleCollectionNewFArticle = em.merge(oldCbCLNo1OfFArticleCollectionNewFArticle);
                    }
                }
            }
            for (FArticle FArticleCollection1OldFArticle : FArticleCollection1Old) {
                if (!FArticleCollection1New.contains(FArticleCollection1OldFArticle)) {
                    FArticleCollection1OldFArticle.setCbCLNo2(null);
                    FArticleCollection1OldFArticle = em.merge(FArticleCollection1OldFArticle);
                }
            }
            for (FArticle FArticleCollection1NewFArticle : FArticleCollection1New) {
                if (!FArticleCollection1Old.contains(FArticleCollection1NewFArticle)) {
                    FCatalogue oldCbCLNo2OfFArticleCollection1NewFArticle = FArticleCollection1NewFArticle.getCbCLNo2();
                    FArticleCollection1NewFArticle.setCbCLNo2(FCatalogue);
                    FArticleCollection1NewFArticle = em.merge(FArticleCollection1NewFArticle);
                    if (oldCbCLNo2OfFArticleCollection1NewFArticle != null && !oldCbCLNo2OfFArticleCollection1NewFArticle.equals(FCatalogue)) {
                        oldCbCLNo2OfFArticleCollection1NewFArticle.getFArticleCollection1().remove(FArticleCollection1NewFArticle);
                        oldCbCLNo2OfFArticleCollection1NewFArticle = em.merge(oldCbCLNo2OfFArticleCollection1NewFArticle);
                    }
                }
            }
            for (FArticle FArticleCollection2OldFArticle : FArticleCollection2Old) {
                if (!FArticleCollection2New.contains(FArticleCollection2OldFArticle)) {
                    FArticleCollection2OldFArticle.setCbCLNo3(null);
                    FArticleCollection2OldFArticle = em.merge(FArticleCollection2OldFArticle);
                }
            }
            for (FArticle FArticleCollection2NewFArticle : FArticleCollection2New) {
                if (!FArticleCollection2Old.contains(FArticleCollection2NewFArticle)) {
                    FCatalogue oldCbCLNo3OfFArticleCollection2NewFArticle = FArticleCollection2NewFArticle.getCbCLNo3();
                    FArticleCollection2NewFArticle.setCbCLNo3(FCatalogue);
                    FArticleCollection2NewFArticle = em.merge(FArticleCollection2NewFArticle);
                    if (oldCbCLNo3OfFArticleCollection2NewFArticle != null && !oldCbCLNo3OfFArticleCollection2NewFArticle.equals(FCatalogue)) {
                        oldCbCLNo3OfFArticleCollection2NewFArticle.getFArticleCollection2().remove(FArticleCollection2NewFArticle);
                        oldCbCLNo3OfFArticleCollection2NewFArticle = em.merge(oldCbCLNo3OfFArticleCollection2NewFArticle);
                    }
                }
            }
            for (FArticle FArticleCollection3OldFArticle : FArticleCollection3Old) {
                if (!FArticleCollection3New.contains(FArticleCollection3OldFArticle)) {
                    FArticleCollection3OldFArticle.setCbCLNo4(null);
                    FArticleCollection3OldFArticle = em.merge(FArticleCollection3OldFArticle);
                }
            }
            for (FArticle FArticleCollection3NewFArticle : FArticleCollection3New) {
                if (!FArticleCollection3Old.contains(FArticleCollection3NewFArticle)) {
                    FCatalogue oldCbCLNo4OfFArticleCollection3NewFArticle = FArticleCollection3NewFArticle.getCbCLNo4();
                    FArticleCollection3NewFArticle.setCbCLNo4(FCatalogue);
                    FArticleCollection3NewFArticle = em.merge(FArticleCollection3NewFArticle);
                    if (oldCbCLNo4OfFArticleCollection3NewFArticle != null && !oldCbCLNo4OfFArticleCollection3NewFArticle.equals(FCatalogue)) {
                        oldCbCLNo4OfFArticleCollection3NewFArticle.getFArticleCollection3().remove(FArticleCollection3NewFArticle);
                        oldCbCLNo4OfFArticleCollection3NewFArticle = em.merge(oldCbCLNo4OfFArticleCollection3NewFArticle);
                    }
                }
            }
            for (FCatalogue FCatalogueCollectionOldFCatalogue : FCatalogueCollectionOld) {
                if (!FCatalogueCollectionNew.contains(FCatalogueCollectionOldFCatalogue)) {
                    FCatalogueCollectionOldFCatalogue.setCbCLNoParent(null);
                    FCatalogueCollectionOldFCatalogue = em.merge(FCatalogueCollectionOldFCatalogue);
                }
            }
            for (FCatalogue FCatalogueCollectionNewFCatalogue : FCatalogueCollectionNew) {
                if (!FCatalogueCollectionOld.contains(FCatalogueCollectionNewFCatalogue)) {
                    FCatalogue oldCbCLNoParentOfFCatalogueCollectionNewFCatalogue = FCatalogueCollectionNewFCatalogue.getCbCLNoParent();
                    FCatalogueCollectionNewFCatalogue.setCbCLNoParent(FCatalogue);
                    FCatalogueCollectionNewFCatalogue = em.merge(FCatalogueCollectionNewFCatalogue);
                    if (oldCbCLNoParentOfFCatalogueCollectionNewFCatalogue != null && !oldCbCLNoParentOfFCatalogueCollectionNewFCatalogue.equals(FCatalogue)) {
                        oldCbCLNoParentOfFCatalogueCollectionNewFCatalogue.getFCatalogueCollection().remove(FCatalogueCollectionNewFCatalogue);
                        oldCbCLNoParentOfFCatalogueCollectionNewFCatalogue = em.merge(oldCbCLNoParentOfFCatalogueCollectionNewFCatalogue);
                    }
                }
            }
            em.getTransaction().commit();
        } catch (Exception ex) {
            String msg = ex.getLocalizedMessage();
            if (msg == null || msg.length() == 0) {
                Integer id = FCatalogue.getCbMarq();
                if (findFCatalogue(id) == null) {
                    throw new NonexistentEntityException("The fCatalogue with id " + id + " no longer exists.");
                }
            }
            throw ex;
        } finally {
            if (em != null) {
                em.close();
            }
        }
    }

    public void destroy(Integer id) throws NonexistentEntityException {
        EntityManager em = null;
        try {
            em = getEntityManager();
            em.getTransaction().begin();
            FCatalogue FCatalogue;
            try {
                FCatalogue = em.getReference(FCatalogue.class, id);
                FCatalogue.getCbMarq();
            } catch (EntityNotFoundException enfe) {
                throw new NonexistentEntityException("The FCatalogue with id " + id + " no longer exists.", enfe);
            }
            FCatalogue cbCLNoParent = FCatalogue.getCbCLNoParent();
            if (cbCLNoParent != null) {
                cbCLNoParent.getFCatalogueCollection().remove(FCatalogue);
                cbCLNoParent = em.merge(cbCLNoParent);
            }
            Collection<FArticle> FArticleCollection = FCatalogue.getFArticleCollection();
            for (FArticle FArticleCollectionFArticle : FArticleCollection) {
                FArticleCollectionFArticle.setCbCLNo1(null);
                FArticleCollectionFArticle = em.merge(FArticleCollectionFArticle);
            }
            Collection<FArticle> FArticleCollection1 = FCatalogue.getFArticleCollection1();
            for (FArticle FArticleCollection1FArticle : FArticleCollection1) {
                FArticleCollection1FArticle.setCbCLNo2(null);
                FArticleCollection1FArticle = em.merge(FArticleCollection1FArticle);
            }
            Collection<FArticle> FArticleCollection2 = FCatalogue.getFArticleCollection2();
            for (FArticle FArticleCollection2FArticle : FArticleCollection2) {
                FArticleCollection2FArticle.setCbCLNo3(null);
                FArticleCollection2FArticle = em.merge(FArticleCollection2FArticle);
            }
            Collection<FArticle> FArticleCollection3 = FCatalogue.getFArticleCollection3();
            for (FArticle FArticleCollection3FArticle : FArticleCollection3) {
                FArticleCollection3FArticle.setCbCLNo4(null);
                FArticleCollection3FArticle = em.merge(FArticleCollection3FArticle);
            }
            Collection<FCatalogue> FCatalogueCollection = FCatalogue.getFCatalogueCollection();
            for (FCatalogue FCatalogueCollectionFCatalogue : FCatalogueCollection) {
                FCatalogueCollectionFCatalogue.setCbCLNoParent(null);
                FCatalogueCollectionFCatalogue = em.merge(FCatalogueCollectionFCatalogue);
            }
            em.remove(FCatalogue);
            em.getTransaction().commit();
        } finally {
            if (em != null) {
                em.close();
            }
        }
    }

    public List<FCatalogue> findFCatalogueEntities() {
        return findFCatalogueEntities(true, -1, -1);
    }

    public List<FCatalogue> findFCatalogueEntities(int maxResults, int firstResult) {
        return findFCatalogueEntities(false, maxResults, firstResult);
    }

    private List<FCatalogue> findFCatalogueEntities(boolean all, int maxResults, int firstResult) {
        EntityManager em = getEntityManager();
        try {
            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
            cq.select(cq.from(FCatalogue.class));
            Query q = em.createQuery(cq);
            if (!all) {
                q.setMaxResults(maxResults);
                q.setFirstResult(firstResult);
            }
            return q.getResultList();
        } finally {
            em.close();
        }
    }

    public FCatalogue findFCatalogue(Integer id) {
        EntityManager em = getEntityManager();
        try {
            return em.find(FCatalogue.class, id);
        } finally {
            em.close();
        }
    }

    public int getFCatalogueCount() {
        EntityManager em = getEntityManager();
        try {
            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
            Root<FCatalogue> rt = cq.from(FCatalogue.class);
            cq.select(em.getCriteriaBuilder().count(rt));
            Query q = em.createQuery(cq);
            return ((Long) q.getSingleResult()).intValue();
        } finally {
            em.close();
        }
    }
    
}
